home *** CD-ROM | disk | FTP | other *** search
- /*
- main.c
- */
-
- #include "FolderUtils.h"
- #include "Extract.h"
- #include "Error.h"
- #include "string.h"
-
-
- Handle foom = NULL ;
- short idBase = 128 ;
-
-
- static void
- InitMac ( long stackSpace ) {
- if ( stackSpace ) {
- SetApplLimit ( CurStackBase - stackSpace ) ;
- }
- MaxApplZone ( ) ;
-
- InitGraf ( & qd . thePort ) ;
- InitFonts ( ) ;
- InitWindows ( ) ;
- InitMenus ( ) ;
- TEInit ( ) ;
- InitDialogs ( NULL ) ;
- }
-
-
- static void
- DoExtract ( short vRefNum , long parID , unsigned char * fileName ) {
-
- short refNum ;
- Handle text ;
- long size ;
-
- Error ( HOpenDF ( vRefNum , parID , fileName , fsRdWrPerm , & refNum ) ) ;
- Error ( GetEOF ( refNum , & size ) ) ;
- text = NewHandle ( size ) ;
- if ( ! text ) {
- Error ( MemError ( ) ) ;
- }
- HLock ( text ) ;
- Error ( FSRead ( refNum , & size , * text ) ) ;
- HUnlock ( text ) ;
-
- PtrAndHand ( "\r/* " , foom , 4 ) ;
- PtrAndHand ( & fileName [ 1 ] , foom , fileName [ 0 ] ) ;
- PtrAndHand ( " */\r" , foom , 4 ) ;
- Error ( MemError ( ) ) ;
-
- Extract ( text , foom , idBase , 1 ) ;
- idBase ++ ;
-
- Error ( SetFPos ( refNum , fsFromStart , 0L ) ) ;
- size = GetHandleSize ( text ) ;
- Error ( SetEOF ( refNum , size ) ) ;
- HLock ( text ) ;
- Error ( FSWrite ( refNum , & size , * text ) ) ;
- Error ( FSClose ( refNum ) ) ;
- DisposeHandle ( text ) ;
- }
-
-
- static void
- ScanFolder ( short vRefNum , long parID ) {
-
- CInfoPBRec rec ;
- Str63 fileName ;
- int ix ;
- char * foom ;
- short err ;
-
- memset ( & rec , 0 , sizeof ( rec ) ) ;
- for ( ix = 1 ; ix > 0 ; ix ++ ) {
- rec . hFileInfo . ioVRefNum = vRefNum ;
- rec . hFileInfo . ioDirID = parID ;
- rec . hFileInfo . ioNamePtr = fileName ;
- rec . hFileInfo . ioFDirIndex = ix ;
- if ( err = PBGetCatInfoSync ( & rec ) ) {
- if ( err == fnfErr ) {
- break ;
- } else {
- Error ( err ) ;
- }
- }
- foom = ( char * ) fileName ;
- foom += fileName [ 0 ] ;
- foom [ 1 ] = 0 ;
- foom -= 1 ;
- if ( ! strcmp ( foom , ".c" ) || ! strcmp ( --foom , ".cp" ) ||
- ! strcmp ( --foom , ".cpp" ) ) {
- DoExtract ( vRefNum , parID , fileName ) ;
- }
- }
- }
-
-
- void
- main ( void ) {
-
- short vRefNum = 0 ;
- long parID = 0 ;
- StandardFileReply reply ;
- short refNum ;
- long size ;
- FSSpec fss ;
-
- InitMac ( 0 ) ;
-
- StandardPutFile ( "\PSave Rez source:" , "\PLiterals.r" , & reply ) ;
- if ( ! reply . sfGood ) {
- ExitToShell ( ) ;
- }
- Error ( FSpCreate ( & reply . sfFile , 'KAHL' , 'TEXT' , reply . sfScript ) ) ;
- foom = NewHandle ( 0L ) ;
- if ( ! foom ) {
- Error ( MemError ( ) ) ;
- }
- PtrAndHand ( "#include \"Types.r\"\r\r" , foom , 20 ) ;
-
- if ( GetAFolderFSS ( & fss , "\PSelect a folder containing C source" ) ) {
- vRefNum = fss . vRefNum ;
- Error ( GetFolderID ( & fss , & parID ) ) ;
- ScanFolder ( vRefNum , parID ) ;
- }
- Error ( FSpOpenDF ( & reply . sfFile , fsRdWrPerm , & refNum ) ) ;
- size = GetHandleSize ( foom ) ;
- Error ( SetEOF ( refNum , size ) ) ;
- HLock ( foom ) ;
- Error ( FSWrite ( refNum , & size , * foom ) ) ;
- Error ( FSClose ( refNum ) ) ;
- Error ( FlushVol ( NULL , reply . sfFile . vRefNum ) ) ;
- }
-
-